<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<title>系统设置</title>
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<!--<link rel="stylesheet" href="../../css/CFNetPP_Base.css">-->
		<link rel="stylesheet" href="../../css/base.css"/>
		<script type="text/javascript" src="../../script/jquery.min.js"></script>
		<script src="../../script/mui.min.js"></script>
		<script src="../../script/common.js"></script>
		<style type="text/css" media="screen">
			input[type=time] {
				line-height: 12px;
				width: auto;
				height: 20px;
				margin-bottom: 0;
				padding: 0 15px;
				-webkit-user-select: text;
				border: none;
				border-radius: none;
				outline: 0;
				background-color: #fff;
				-webkit-appearance: none;
			}
			.mui-table-view .mui-table-view-cell .mui-active {
				background: #18b4ed;
			}
			.mui-switch.mui-active {
				border-color: #18b4ed;
				background-color: #18b4ed;
			}
		</style>
	</head>
	<body>
		<div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
		<div class="base_navigation_bar base_style_color base_navigation_item_bar">
			<a class="base_left_item" href="#" onclick="backClick()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span>系统设置</span>
			<a class="base_right_item base_hide_item"> </a>
		</div>
		<div class="setmsg" style="margin-top: 68px">
			<ul class="mui-table-view base_dark_grey">
				<!--		<li class="mui-table-view-cell">
				<span >消息通知</span>
				<div id="mySwitchMsg" class="mui-switch switchsize mui-switch-mini mui-active">
				<div class="mui-switch-handle"></div>
				</div>
				</li>-->
				<li class="mui-table-view-cell" onclick="showCleanCache()">
					<span>清除缓存</span>
					<span id="cacheSize" class="floatright base_light_gray base_content_font">0.0B</span>
				</li>
				<!-- <li class="mui-table-view-cell">
				<span>签到提醒</span>
				<div id="mySwitchTixing" class="mui-switch switchsize mui-switch-mini">
				<div class="mui-switch-handle"></div>
				</div>
				</li>
				<li class="mui-table-view-cell">
				<span>提醒时间</span>
				<input id="reminder_time" class="settime base_light_gray base_content_font" type="time" value="09:30"></input>
				</li> -->
			</ul>
		</div>
		<!--清除缓存-->
		<div id="cleanCache" class="weui_dialog_confirm" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title">确定清除缓存？</strong>
				</div>
				<div class="weui_dialog_bd"></div>
				<div class="weui_dialog_ft">
						<a onclick="cleanCancel()" href="#" class="weui_btn_dialog default"  style="color:#18b4ed">取消</a>
					<a onclick="cleanConfirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/databaseOperation.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script type="text/javascript" src="../../script/localNotifi.js"></script>
	<script type="text/javascript">
		// $(function(){
		//     // 消息通知开关事件
		//     document.getElementById("mySwitchMsg").addEventListener("toggle",function(event){
		//       if(event.detail.isActive){
		//         console.log("你启动了开关");
		//       }else{
		//         console.log("你关闭了开关");
		//       }
		//     })
		//     // 签到提醒开关事件
		//     document.getElementById("mySwitchTixing").addEventListener("toggle",function(event){
		//       if(event.detail.isActive){
		//         console.log("你启动了开关");
		//       }else{
		//         console.log("你关闭了开关");
		//       }
		//     })
		// })
		DBReady = function() {
			bakey();
			var sendMsgStatus = $api.getStorage('msgStatus');
			if (sendMsgStatus == 'true') {
				$("#mySwitchMsg").addClass('mui-active');
			} else if (sendMsgStatus == 'false') {
				$("#mySwitchMsg").removeClass('mui-active');
			}
			var ajpush = api.require('ajpush');
			// 消息通知开关事件
			document.getElementById("mySwitchMsg").addEventListener("toggle", function(event) {
				if (event.detail.isActive) {
					//存储开关打开状态
					ajpush.resumePush(function(ret) {
						if (ret && ret.status) {
							$api.setStorage('msgStatus', 'true');
							loadNotifiStatus();
						}
					});
				} else {
					//存储开关关闭状态
					ajpush.stopPush(function(ret) {
						if (ret && ret.status) {
							$api.setStorage('msgStatus', 'false');
							// //取消签到通知
							// api.cancelNotification({
							//     id: $api.getStorage('signNotifiID')
							// });
							// //取消周报通知
							// api.cancelNotification({
							//     id: $api.getStorage('weeklyNotifiID')
							// });
							// //取消月报通知
							// api.cancelNotification({
							//     id: $api.getStorage('monthNotifiID')
							// });
						}
					});
				}
			});
			setupCache();
		};
		function setupCache() {
			//获取缓存
			api.getCacheSize(function(ret, err) {
				if (ret) {
					// alert(JSON.stringify(ret));
					var cacheSize = bytesToSize(parseInt(ret.size));
					$("#cacheSize").html(cacheSize);
				}
			});
		}

		// 字节转换
		function bytesToSize(bytes) {
			//alert(bytes);
			if ((bytes - 557424) <= 0)
				return '0 KB';
			// if(bytes == 0) return '0 KB';
			var k = 1000;
			var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
			var i = Math.floor(Math.log(bytes) / Math.log(k));
			return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
		}

		// 取消清除
		function cleanCancel() {
			$("#cleanCache").hide();
		}

		// 确定清除
		function cleanConfirm() {
			$("#cleanCache").hide();
			api.clearCache(function(ret, err) {
				if (ret) {
					dropTables(function() {
						api.toast({
							msg : '清除缓存成功！',
							location : 'bottom',
							duration : 2000
						});
						api.getCacheSize(function(ret, err) {
							if (ret) {
								var cacheSize = bytesToSize(parseInt(ret.size));
								$("#cacheSize").html(cacheSize);
							}
						});
						createTables(function(ret) {
							api.sendEvent({
								name : 'refreshMsgNotifi'
							});
						});
					});
				} else {
					// alert(JSON.stringify(err));
				}
			});
		}

		function bakey() {
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				api.closeWin({
				});
			});
		}

		function showCleanCache() {
			$('#cleanCache').show();
		}
	</script>
</html>